GetIJinteger Subroutine

private subroutine GetIJinteger(X, Y, grid, i, j, check)

returns X and Y coordinate given i and j position in grid(i,j)

Arguments

Type IntentOptional Attributes Name
real(kind=float), intent(in) :: X
real(kind=float), intent(in) :: Y
type(grid_integer), intent(in) :: grid
integer, intent(out) :: i
integer, intent(out) :: j
logical, intent(out), optional :: check

return false if i and j are outside grid definition


Source Code

SUBROUTINE GetIJinteger &
!
(X, Y, grid, i, j, check)

IMPLICIT NONE

!Arguments with intent(in):
REAL (KIND = float), INTENT(IN) :: X,Y
TYPE (grid_integer), INTENT(IN) :: grid


!Arguments with intent(out):
INTEGER, INTENT(OUT) :: i, j
LOGICAL, OPTIONAL, INTENT(OUT) :: check !!return false if i and j are outside grid definition
!------------end of declaration------------------------------------------------

j = INT ( (X - grid % xllcorner) / grid %cellsize ) + 1 
i = INT ( (grid % yllcorner + grid % idim * grid % cellsize - y) &
          / grid%cellsize ) + 1

IF (PRESENT (check)) THEN
  IF (i < 1 .OR. i > grid % idim .OR. j < 1 .OR. j > grid % jdim ) THEN
    check = .FALSE.
  ELSE
    check = .TRUE.
  END IF
END IF

END SUBROUTINE GetIJinteger